/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UserManager;
import DataConnect.*;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
/**
 *
 * @author MyLaptop
 */
public class Users {
    public int userID;
    public  String userName;
    public String userPassword;
    public String userTypeCode;
    public int userActive;
    public int empID;
    Connection Con;
    Statement Sta;
    public Users()
    {
        
    }

    public int getEmpID() {
        return empID;
    }

    public int getUserActive() {
        return userActive;
    }

    public int getUserID() {
        return userID;
    }

    public String getUserName() {
        return userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public String getUserTypeCode() {
        return userTypeCode;
    }

    
    
    public void setUserTypeCode(String userTypeCode) {
        this.userTypeCode = userTypeCode;
    }

   

    public void setEmpID(int empID) {
        this.empID = empID;
    }

    public void setUserActive(int userActive) {
        this.userActive = userActive;
    }

    public void setUserID(int userID) {
        this.userID = userID;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

   
    
     public static Vector getAllUser() throws SQLException{
        Vector v = new Vector();
        try {
            ResultSet rs = DBHelper.executeQuery("spGetAllUser");
            while(rs.next()){
                Users objUser = new Users();
                objUser.userID = rs.getInt(1);
                objUser.userName = rs.getString(2);
                objUser.userPassword = rs.getString(3);
                objUser.userTypeCode = rs.getString(4);
                objUser.userActive = rs.getInt(5);
                objUser.empID = rs.getInt(6);
               
                v.add(objUser);
            }
        } catch (SQLException ex) {
            
        }
        return v;        
    }   
    
     public static int changePassword(String pass) throws SQLException{
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(pass);
            i = DBHelper.executeUpdate("spChangePassword",paramList);
        } catch (SQLException ex) {
            
        }
        return i;
    }
    
    public static int insertUser(Users objUser) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(objUser.userName);
            paramList.add(objUser.userPassword);
            paramList.add(objUser.userTypeCode);
            paramList.add(objUser.userActive);
            paramList.add(objUser.empID);
            i = DBHelper.executeUpdate("spInsertUser",paramList);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }
    public static int updateUser(Users objUser) throws SQLException {
        int i=0;
        try {            
            Vector paramList = new Vector();
            paramList.add(objUser.userID);
            paramList.add(objUser.userName);
            paramList.add(objUser.userPassword);
            paramList.add(objUser.userTypeCode);
            paramList.add(objUser.userActive);
            paramList.add(objUser.empID);
            i = DBHelper.executeUpdate("spUpdateUser",paramList);
        } catch(SQLException sqlex) {
            
        }
        return i;
    }
    
     public static int deleteUser(String userName) throws SQLException {
        int i=0;
        try {
            Vector paramList=new Vector();
            paramList.add(userName);
            i=DBHelper.executeUpdate("spDeleteUser",paramList);
        } catch(SQLException sqlex) {
            
        }
        return i;
    }
    
//    public static Vector getUserCodeForOrders(Vector vList) throws SQLException{
//        Vector v = new Vector();
//        try {
//            ResultSet rs = DBHelper.executeQuery("spGetCodeByName",vList);
//            while(rs.next()){
//                Users objUser = new Users();
//                objUser.userCode = rs.getInt(1);
//                v.add(objUser);
//            }
//        } catch (SQLException ex) {
//            
//        }
//        return v;        
//    }    
    
}
